package com.dfbz.Dao;

import com.dfbz.model.Student;
import com.dfbz.utils.JDBCUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class StudentDao {

    public List<Student> findAll(){
       Connection connection = null;
       PreparedStatement statement = null;
       ResultSet resultSet = null;
       List<Student> list = new ArrayList<>();
        try {
            Student student = null;
            connection = JDBCUtil.getConnection();
            statement = connection.prepareStatement("select * from student");
            resultSet = statement.executeQuery();
            while(resultSet.next()){
                String id = resultSet.getString("id");
                String name = resultSet.getString("name");
                String phone = resultSet.getString("phone");
                String address = resultSet.getString("address");
                System.out.println("id "+id+" name "+name+" phone "+phone+" address "+address);
                student = new Student(id,name,phone,address);
                list.add(student);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCUtil.close(resultSet,statement,connection);
        }
        return list;
    }

    public void add(){

    }

    public void delete(){

    }

    public void  update(){

    }


}
